@echo off
rem     This is a sample batch file to run metafont, convert the GF file to
rem     the PK format and store the PK font in the appropriate directory. It
rem     is meant to be called by dviwin and that's the reason for the absence
rem     of any parameter checking. It also assumes that metafont and gftopk
rem     are operating properly. This sample file attempts to cover as many
rem     devices as possible; you will probably get better and faster results
rem     if you write a smaller and more specialized batch file.
rem
rem     The plain base is a prerequisite: make sure that you generate it by
rem     running inimf on plain.mf, then input the file modes.mf (version 2.1
rem     or later; you can get it from the directory /tex-archive/fonts/modes
rem     at the CTAN hosts: ftp.shsu.edu, ftp.dante.de and ftp.tex.ac.uk; some
rem     modes will not work properly with earlier versions of the modes.mf
rem     file) and finally dump the format file. If you don't know what I am
rem     talking about, please read the documentation that comes with the
rem     metafont program, as well as the Metafont book.
rem
rem     You WILL need to modify the routine to place the PK files in the
rem     proper directory; the current method uses the environment variable
rem     DVIFONTS which is assumed to contain the base directory for the PK
rem     fonts. Any square-pixel fonts are assumed to be stored in the
rem     directories  $(DVIFONTS)\X  where X is the resolution of the font.
rem     Non-square-pixel fonts are assumed to stored in the directories
rem     $(DVIFONTS)\XxY where X is the horizontal resolution and Y is the
rem     vertical resolution.
rem
rem     It is trivial to modify the name of metafont and the base directory;
rem     just select the proper values for the first two statements after
rem     these comments. If you use another directory structure, you need
rem     to modify the next two statements.
rem
rem     If metafont does not recognize any other modes, it will generate
rem     its standard proofing fonts which are HUGE and inappropriate for
rem     your device. In that case, get the file modes.mf from CTAN and
rem     generate the plain base again using the command:
rem             inimf plain;input modes;dump
rem     Then you need to copy plain.bas to the appropriate directory. You
rem     may need to replace "inimf" by "mf -i" for some Metafont versions.
rem
rem     Here are the parameters passed by dviwin:
rem             %1:     path
rem             %2:     fontname
rem             %3:     mag
rem             %4:     driver           (of current dvi file)
rem             %5:     xres            (hor. resolution of font)

rem set PATH=C:\program~1\texmf\miktex\bin

rem     If the font already exists, don't do anything
if exist "%1\%2.pk" goto GET_OUT

rem     If you want to switch to the directory of the current dvi file,
rem     uncomment the next two statements. This is useful if you prefer
rem     to keep some mf sources in the dvi file directory instead of the
rem     MFINPUTS directory.
rem %7:
rem cd %8

rem Assuming window is on drive C!
cd %windir%\temp

rem     Initialize device and magstep to empty
set PK_DEV=jetiiisi
set PK_MAG=

rem     Devices with square pixels. The current code supports the resolutions
rem     used by the Beebe drivers for the screen, 300dpi and 400dpi laser
rem     and inkjet printers, 600dpi laserjets, 24-pin printers at 180x180
rem     and 360x360dpi.

del "%1.*.gf"
set PK_MAG=%3
if +%PK_DEV%==+ goto UNKNOWN

echo on
mf.exe \scrollmode;mode:=%PK_DEV%;mag:=%3;input "%~2"
@echo off

rem at this point all errors are in the files, so we continue anyway
rem if errorlevel 1 goto ERROR_EXIT

rem     Find out if the directories already exist to avoid
rem     any warning messages
mkdir "%~1"

rem call gf2pk to put the font on its final location and format
set GF_EXT=%5gf

echo on
gftopk "%~2.%GF_EXT%" "%~1\%~2.pk"
@echo off

rem     If you want to copy the TFM file to an appropriate directory,
rem     here is the place to do it, otherwise get rid of everything!
del "%~2.%GF_EXT%"
del "%~2.log"
del "%~2.tfm"
goto GETOUT

:UNKNOWN
echo I don't know the metafont mode for this device. Please
echo add this information to the file %0

:ERROR_EXIT
rem     The next line creates a small file in the TEMP directory. This
rem     signals the error to the "genall.bat" file, so it doesn't call
rem     dviwin again when running under NT.
echo ERROR > %windir%\temp\error$_$

:GETOUT
